﻿using System;
using SearchContract.Pages;
using SearchContract.ViewModels;
using WinRTFramework.FrameworkConfiguration;

namespace SearchContract.WinRTFrameworkConfiguration
{
    class ViewViewModelMapper : IViewViewModelMapper
    {
        private IIoCAdapter _ioCAdapter;

        public ViewViewModelMapper(IIoCAdapter ioCAdapter)
        {
            _ioCAdapter = ioCAdapter;
        }

        public Type GetViewTypeForViewModelType(Type viewModelType, object navigationParameter)
        {
            if (viewModelType == typeof(MainPageViewModel))
                return typeof (MainPage);

            if (viewModelType == typeof(DefaultSearchablePageViewModel))
                return typeof(DefaultSearchablePage);

            if (viewModelType == typeof(InferiorSearchablePageViewModel))
                return typeof(InferiorSearchablePage);

            throw new ArgumentOutOfRangeException("viewModelType");
        }

        public object GetViewModelForView(Type viewType, object navigationParameter)
        {
            if (viewType == typeof(MainPage))
                return _ioCAdapter.GetInstanceOfType(typeof(MainPageViewModel));

            if (viewType == typeof(DefaultSearchablePage))
                return _ioCAdapter.GetInstanceOfType(typeof(DefaultSearchablePageViewModel));

            if (viewType == typeof(InferiorSearchablePage))
                return _ioCAdapter.GetInstanceOfType(typeof(InferiorSearchablePageViewModel));

            throw new ArgumentOutOfRangeException("viewType");
        }
    }
}
